package com.ss.tmall.util;

/**
 * @Author: ShengShuai
 * @Description:
 * @Date: Created in 上午 10:53  2017/12/23 0023
 * @Modified By:
 */
public class Page {
    private static final int defaultcount = 5;
    private int start;
    private int count;
    private int total;
    private String param;

    public Page() {
        count = defaultcount;

    }

    public Page(int start, int count) {
        this();
        this.start = start;
        this.count = count;
    }

    public static int getDefaultcount() {
        return defaultcount;
    }

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public String getParam() {
        return param;
    }

    public void setParam(String param) {
        this.param = param;
    }

    public boolean isHasPreviouse() {
        if (start == 0) {
            return false;
        }
        return true;
    }

    public boolean isHasNext() {
        if (start == getlast()) {
            return false;

        }
        return true;
    }

    public int getlast() {
        int last;
//求最后一页的第一个数
        if (0 == total % count) {
            last = total - count;
        } else {
            last = total - total % count;
        }
        last = last < 0 ? 0 : last;
        return last;

    }

    public int getTotalPage() {
        int totalpage;
        if (0 == total % count) {
            totalpage = total / count;
        } else {
            totalpage = total / count + 1;
        }
        if (0 == total) {
            totalpage = 1;

        }
        return totalpage;
    }

    @Override
    public String toString() {
        return "Page{" +
                "start=" + start +
                ", count=" + count +
                ", total=" + total +
                ", param='" + param + '\'' +
                '}';
    }
}
